package com.mjh.zhujianju.controller.agency;

import javax.annotation.Resource;

import com.mjh.zhujianju.util.ApiConstant;
import com.mjh.zhujianju.util.JsonResult;
import com.mjh.zhujianju.vo.agency.DepartmentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.livew.framework.base.controller.RestBaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.enums.EUserRoleType;
import com.mjh.zhujianju.model.agency.DepartmentEO;
import com.mjh.zhujianju.service.agency.DepartmentService;

import java.util.List;

/***
 * 
 *@ClassName: DepartmentController 
 * @Description  部门
 * @author wangdong
 * @date 2018年8月6日 下午11:20:57   
 * @version V1.0
 */
@RestController
@RequestMapping("department")
@Api("部门")
public class DepartmentController{

	@Resource
	private DepartmentService departmentService;

	@ApiOperation(value="部门列表", notes="下拉框用，查询所有部门信息")
	@RequestMapping(value = "/selectList", method = RequestMethod.GET)
	public ResponseEntity<JsonResult> getAnnouncement (){
		JsonResult result = new JsonResult();
		try {
			List<DepartmentEO> list = departmentService.getAll();
			result.setResult(list);
			result.setStatus(ApiConstant.MSG_SUCCESS);
		}catch (Exception e){
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}

	@ApiOperation(value="部门下的人员", notes="查询部门下的所有人员信息")
	@RequestMapping(value = "/getDepUsers", method = RequestMethod.GET)
	public ResponseEntity<JsonResult> getDepUsers (String userIds){
		JsonResult result = new JsonResult();
		try {
			String type = EUserRoleType.user.getCode();//工作人员
			List<DepartmentVO> list = departmentService.queryDepartmentAndUserForList(userIds,type);
			result.setResult(list);
			result.setStatus(ApiConstant.MSG_SUCCESS);
		}catch (Exception e){
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}




}
